package com.example.administrator.testhttpclient;

import android.util.Log;
import android.view.View;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/11/24.
 */
public class CatchTeacherInf {
    List<Teacher> teachers  = new ArrayList<Teacher>();


    public void catchData() {
        new Thread() {
            @Override
            public void run() {
                HttpClient client = new DefaultHttpClient();
                HttpUriRequest request = new HttpGet("http://121.248.70.214/jwweb/ZNPK/Private/List_JS.aspx?xnxq=20150&js=");
                String ss = null;
                try {
                    HttpResponse response = client.execute(request);
                    HttpEntity entity = response.getEntity();
                    ss = EntityUtils.toString(entity);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                Document doc = Jsoup.parse(ss);
                Elements script = doc.getElementsByTag("script");
                String html = script.get(0).html();
                Document hd = Jsoup.parse(html);
                Elements es = hd.getElementsByTag("option");
                for(int i=0;i<es.size();i++) {
                    Teacher teacher  = new Teacher();
                    teacher.setNum(es.get(i).attr("value"));
                    teacher.setTname(es.get(i).text());
                    teachers.add(teacher);
                    Log.i("tiantong", es.get(i).attr("value") + "....");
                    Log.i("tiantong", es.get(i).text());
                }
            }
        }.start();
    }

}
